package com.huang.A01_case;

/**
 * 目标：
 * 找素数
 */
public class Demo7 {
    public static void main(String[] args) {
        System.out.println("共有" + search2(100, 200));

        int count = 0;
        for (int i = 100; i <= 200; i++) {
            if(check(i)){
                count++;
                System.out.println(i);
            }
        }
        System.out.println("共有" + count);

    }

    public static int search1(int start, int end) {
        int count = 0;

        for (int i = start; i <= end; i++) {
            //信号位
            boolean flag = true;
            //从2遍历到该数据的一半进行判断
            for (int j = 2; j <= i / 2; j++) {
                if (i % j == 0) {
                    flag = false;
                    break;
                }
            }
            //根据flag判断是否为素数
            if (flag) {
                count++;
                System.out.println(i);
            }
        }
        return count;
    }

    public static int search2(int start, int end) {
        int count = 0;
        out:
        for (int i = start; i <= end; i++) {
            //从2遍历到该数据的一半进行判断
            for (int j = 2; j <= i / 2; j++) {
                if (i % j == 0) {
                    continue out;
                }
            }
            //为素数
                count++;
                System.out.println(i);
        }
        return count;
    }

    public static boolean check(int data) {
            //从2遍历到该数据的一半进行判断
            for (int j = 2; j <= data / 2; j++) {
                if (data % j == 0) {
                    return false;
                }
            }
            //为素数
            return true;
    }
}